#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

int main()
{
    umask(0);
    //int fd=open("log.txt",O_WRONLY | O_CREAT | O_TRUNC,0666);
    int fd=open("log.txt",O_WRONLY | O_CREAT | O_APPEND,0666);
    int fd1=open("log1.txt",O_WRONLY | O_CREAT | O_APPEND,0666);
    int fd2=open("log2.txt",O_WRONLY | O_CREAT | O_APPEND,0666);
    int fd3=open("log3.txt",O_WRONLY | O_CREAT | O_APPEND,0666);
    
    //if(fd<0)
    //{
    //    perror("open");
    //    return 1;
    //}
    printf("fd:%d\n",fd);
    printf("fd1:%d\n",fd1);
    printf("fd2:%d\n",fd2);
    printf("fd3:%d\n",fd3);
    //写入
    //const char*str="hello iu,123\n";
    //write(fd,str,strlen(str));
    close(fd);
    close(fd1);
    close(fd2);
    close(fd3);
    return 0;
}


/*int main()
{
    const char *s1="hello printf\n";
    printf(s1);

    const char *s2="hello fprintf\n";
    fprintf(stdout,s2);

    const char* s3="hello fputs\n";
    fputs(s3,stdout);

    const char*s4="hello fwrite\n";
    fwrite(s4,strlen(s4),1,stdout);

    return 0;
}*/


/*int main(int argc,char *argv[])
{
    //printf("我是一个进程：%d\n",getpid());
    if(argc!=2)
    {
        printf("Usage:%s filename\n",argv[0]);
        return 2;
    }


    //chdir("/home/iu");更改工作路径
    FILE* fp=fopen(argv[1],"r");
    if(!fp)
    {
        perror("fopen");
        return 1;
    }

    while(1)
    {
        char buf[1024];
        buf[0]=0;
        size_t n=fread(buf,1,sizeof(buf)-1,fp);
        if( n > 0)
        {
            buf[n]=0;
            printf("%s",buf);
        }
        else if(feof(fp))
            break;
    }

    //const char*str="hello iu\n";
    //fwrite(str,strlen(str),1,fp);

    //while(1)
    //{
    //    sleep(1);
    //}

    fclose(fp);
    return 0;
}*/
